/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.common.entity;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import merlion.common.util.Consts;
import merlion.common.util.Consts.PhoneType;

/**
 *
 * @author Zhang Ying
 */
@Entity
public class Phone implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String number;
    private PhoneType phoneType;
    @ManyToOne(targetEntity=Staff.class, cascade={CascadeType.PERSIST},fetch=FetchType.EAGER)
    private Staff staff;
    
    public Phone(){
    }

    public Phone(int i) {
        switch(i){
            case 0: 
                phoneType = Consts.PhoneType.BUSINESS_TEL;
                break;
            case 1:
                phoneType = Consts.PhoneType.BUSINESS_HP;
                break;
            case 2:
                phoneType = Consts.PhoneType.HOME_TEL;
                break;
            case 3:
                phoneType = Consts.PhoneType.HOME_HP;
                break;
            default: break;
        }
    }
    
    public void create(String number, PhoneType phoneType){
        this.setNumber(number);
        this.setPhoneType(phoneType);
    }
    
    public String getPhoneTypeString(){
        if (phoneType.equals(Consts.PhoneType.BUSINESS_HP)){
            return "Business Handphone";
        }else if(phoneType.equals(Consts.PhoneType.BUSINESS_TEL)){
            return "Business Telephone";
        }else if(phoneType.equals(Consts.PhoneType.HOME_HP)){
            return "Home Handphone";
        }else if(phoneType.equals(Consts.PhoneType.HOME_TEL)){
            return "Home Telephone";
        }else {
            return "";
        }
    }
    
    public String getNumber() {
        return number;
    }

    public PhoneType getPhoneType() {
        return phoneType;
    }

    public Long getId() {
        return id;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public void setPhoneType(PhoneType phoneType) {
        this.phoneType = phoneType;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Staff getStaff() {
        return staff;
    }

    public void setStaff(Staff staff) {
        this.staff = staff;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Phone)) {
            return false;
        }
        Phone other = (Phone) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.common.entity.Phone[ id=" + id + " ]";
    }
    
}
